package com.yyb.service.impl;

import com.github.pagehelper.Page;
import com.yyb.common.PageInfo;
import com.yyb.domain.SysLoginInfo;
import com.yyb.dto.SysLoginInfoQueryDTO;
import com.yyb.mapper.SysLoginInfoMapper;
import com.yyb.service.SysLoginInfoService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 * 
 * 
 */
@Service
public class SysLoginInfoServiceImpl extends BaseServiceImpl<SysLoginInfo> implements SysLoginInfoService {

    @Resource
    private SysLoginInfoMapper sysLoginInfoMapper;

    /**
     * 保存登录日志
     *
     * @param sysLoginInfo
     */
    @Override
    public int insertSelective(SysLoginInfo sysLoginInfo) {
        return this.sysLoginInfoMapper.insertSelective(sysLoginInfo);
    }

    /**
     * 分页查询登录日志
     *
     * @param pageInfo
     * @return
     */
    @Override
    public PageInfo<SysLoginInfo, SysLoginInfoQueryDTO> getByPage(PageInfo<SysLoginInfo, SysLoginInfoQueryDTO> pageInfo) {
        Page<SysLoginInfo> infoPage = this.startPage(pageInfo.getPageNumber(), pageInfo.getPageSize());
        List<SysLoginInfo> loginInfoList=this.sysLoginInfoMapper.queryAllLoginInfo(pageInfo.getParams());
        pageInfo.setList(loginInfoList);
        pageInfo.setTotalPage(infoPage.getPages());
        pageInfo.setTotalCount(infoPage.getTotal());
        return pageInfo;
    }

    /**
     * 根据ID删除登录日志
     *
     * @param loginInfoId
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Long loginInfoId) {
        return this.sysLoginInfoMapper.deleteByPrimaryKey(loginInfoId);
    }

    /**
     * 批量删除登陆日志
     *
     * @param loginInfoIds
     * @return
     */
    @Override
    public int deleteByPrimaryKeys(Long[] loginInfoIds) {
        if(loginInfoIds==null|| loginInfoIds.length==0){
            return 0;
        }
        return this.sysLoginInfoMapper.deleteByPrimaryKeys(loginInfoIds);
    }

    /**
     * 清空登陆日志
     *
     * @return
     */
    @Override
    public int deleteAllLoginInfo() {
        return this.sysLoginInfoMapper.deleteAllLoginInfo();
    }
}
